﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Mirror;

public class Phone_PlayerContolT : NetworkBehaviour
{

    public GameObject cam;
    public GameObject joy;

    private CharacterController cc;
    public float moveSpeed = 5;
    private float horizontalWrapMode, verticalMove;
    private Vector3 dir;
    public Joystick joystick;

    public override void OnStartLocalPlayer()
    {
        cam.SetActive(true);
        joy.SetActive(true);
        //Camera.main.transform.SetParent(transform);
        //Camera.main.transform.localPosition = Vector3.zero;
    }

    private void Awake()
    {
        cc = GetComponent<CharacterController>();
    }

    // Update is called once per frame
    void Update()
    {
        if (NetState.isNet == true)//联网模式角色移控制
        {
            //print("联网模式");
            if (!isLocalPlayer)
            {
                //floattingInfo.transform.LookAt(Camera.main.transform);
                return;
            }
            horizontalWrapMode = joystick.Horizontal * moveSpeed;
            verticalMove = joystick.Vertical * moveSpeed;
            dir = transform.forward * verticalMove;

            //transform.Rotate(0, horizontalWrapMode / 10, 0);

            //transform.rotation = Quaternion.AngleAxis(horizontalWrapMode * 20, Vector3.up);

            cc.Move(dir * Time.deltaTime);

            //print("yaogan");


            if (Input.GetKeyDown(KeyCode.C))
            {
                //ChangePlayerNameAndColor();
                //print("anxia");
            }
            
        }
    }
}
